<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>新增角色addRole </title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />

	<style>
		body{
			background:#eeeeee;
		}
		.Role{
			padding-top:30px;
		}
		.Role p {
			text-align:center;
			margin-top:10px;
		}
		.Role p input[type=text]{
			width:200px;
			height:27px;
			border:1px solid #dadada;
			margin-left:5px;
			font-size:14px;
			font-family:"微软雅黑";
			padding-left:10px;
		}
		.Role p input[type=radio]{
			position:relative;
			top:5px;
			right:5px;
			margin-left:10px;
		}
		.btnBox{
			width:100%;
			text-align:center;
			margin-top:15px;
		}
		.cancel{
			margin-left:15px;
			background-color:#afb1b0;
		}
	</style>
	<body>
		<div class="Role">
			<p>角色名称<span><input class='roleName' type="text"  /></span></p>
			<p>角色描述<span><input class='roleDes' type="text"  /></span></p>
			<p>状态<span><input type='radio' value='vd' name="status" />有效<input type='radio' value='ud' name="status" />无效</span></p>			
		</div>
		
		<div class='btnBox'>
			<button class='Dolo_btn sure'>确认</button>
			<button class='Dolo_btn cancel'>取消</button>
		</div>
		
		
	</body>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
		<!-- 引入my97日期时间控件 -->
		<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js" charset="utf-8"></script>	
		<script type="text/javascript" src="../js/common.js" ></script>
		<script>
		//_____________________________________________________________________________页面展开
		if(getHref().postId){			
			//_____________________________________________________________________________修改角色确定	
			var postId = getHref().postId
			$(".roleName").prop("disabled",true)			
			$.get("../role/editPage?id="+postId+"&temp="+Math.random,function(data){
				data = JSON.parse(data)
				console.log(data)
				$(".roleName").val(data.data.name)
				$(".roleDes").val(data.data.description)
				if(data.data.state=="vd"){
					$("input[value=vd]").prop("checked",true)
				}if(data.data.state=="ud"){
					$("input[value=ud]").prop("checked",true)
				}															
			})
			$(".sure").click(function(){
				
				var submitMess = {};
				var name = $(".roleName").val();
				var description = $(".roleDes").val();
				var state = $("input[type=radio]:checked").val();
				if(name==""||state==undefined){
					layer.msg("角色名称和状态为必填项！",{icon: 2,time:2000},function(){
						
					})
					return false;
				}
				submitMess.name = name;
				submitMess.description = description;
				submitMess.state = state;
				submitMess.id = postId;
				layer.msg('修改中...', {icon: 16,shade: 0.01});
				$.ajax({
					type:"post",
					url:"../role/edit?temp="+Math.random(),
					contentType:'application/json;charset=utf-8',
					async:true,
					data:JSON.stringify(submitMess),
					success:function(data){
						data=JSON.parse(data)
						if(data.status=="1001"){
							layer.msg('编辑角色成功', {icon: 1,time:1000},function(){
								var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
								parent.layer.close(index);//关闭弹窗
							})	
						}if(data.status=="1002"){
							layer.msg("编辑角色失败,"+data.message,{icon: 2,time:2000},function(){
								
							})
						}
					}
						
				});	
			})
		}else{						
			//_____________________________________________________________________________新增角色确定
			$(".sure").click(function(){
				
				var submitMess = {};
				var name = $(".roleName").val();
				var description = $(".roleDes").val();
				var state = $("input[type=radio]:checked").val();
				if(name==""||state==undefined){
					layer.msg("角色名称和状态为必填项！",{icon: 2,time:2000},function(){
						
					})
					return false;
				}
				submitMess.name = name;
				submitMess.description = description;
				submitMess.state = state;
				layer.msg('添加中...', {icon: 16,shade: 0.01});
				$.ajax({
					type:"post",
					url:"../role/add?temp="+Math.random(),
					contentType:'application/json;charset=utf-8',
					async:true,
					data:JSON.stringify(submitMess),
					success:function(data){
						data=JSON.parse(data)
						if(data.status=="1001"){
							layer.msg('创建角色成功', {icon: 1,time:1000},function(){
								var index = parent.layer.getFrameIndex(window.name);//获取弹窗索引
								parent.layer.close(index);//关闭弹窗
							})	
						}if(data.status=="1002"){
							layer.msg("创建角色失败,"+data.message,{icon: 2,time:2000},function(){
								
							})
						}
					}
						
				});	
			})
			
		}
		//_____________________________________________________________________________取消按钮
			$(".cancel").click(function(){
				closeWin()
			})	
		
		</script>
		
			
</html>
